package Arrays;

/**
 * 作者:hfj
 * 功能:283.移动零
 * 日期: 2025/11/11 16:38
 */
public class MoveZeroes {
    public static void main(String[] args) {
        int[] nums = {0,1,0,3,12};
        moveZeroes(nums);
        for (int i = 0; i < nums.length; i++) {
            System.out.println(nums[i]);
        }
    }

    public static void moveZeroes(int[] nums) {
        int index = 0;//临时指针
        //先把不是0的往前移
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != 0){
                nums[index++] = nums[i];
            }
        }

        //剩下则全为0
        for (int i = index; i < nums.length; i++) {
            nums[i] = 0;
        }
    }
}
